﻿using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace ESSManageService.API.Filter
{
    public class MinimalSchemasFilter : ISchemaFilter
    {
        /// <summary>
        /// schemas过滤器
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="context"></param>
        public void Apply(OpenApiSchema schema, SchemaFilterContext context)
        {
            // 移除所有属性示例值
            foreach (var prop in schema.Properties)
            {
                prop.Value.Example = null;
                prop.Value.Default = null;
            }

            // 可选：隐藏复杂类型
            if (context.Type.IsClass && context.Type != typeof(string))
            {
                schema.Properties.Clear();
                schema.Type = "object";
                schema.AdditionalPropertiesAllowed = true;
            }
            
        }
    }
}
